// 工作流画布相关接口
import axios from '../interceptors.js'
import originAxios from 'axios'
import config from '../config'

// 数据-树分类
export const getCategories = () => {
  return axios({
    url: '/pipeline/task-categories',
    timeout: 600000000
  })
};

// 数据-树节点查看
export const getDataTrees = () => {
  return axios({
    url: '/pipeline/task-nodes',
    timeout: 600000000
  })
};

// 任务镜像类型
export const getImageTypes = () => {
  return axios({
    url: '/pipeline/task-types',
    timeout: 600000000
  })
};

// 自定义创建节点
export const createCustomNode = (data) => {
  return axios({
    url: '/pipeline/pipeline-tasks',
    method: 'post',
    data
  })
}

// 编辑自定义节点
export const updateCustomNode = (data) => {
  return axios({
    url: '/pipeline/pipeline-tasks',
    method: 'put',
    data,
    timeout: 600000000
  })
}

// 创建拖拽节点
export const createDragNode = (data) => {
  return axios({
    url: '/pipeline/pipeline-tasks/tasknode',
    method: 'post',
    data
  })
}

// 获取节点的编辑信息
export const getNodeInfo = (data) => {
  return axios({
    url: `/pipeline/pipeline-tasks/${data.id}`,
    timeout: 600000000
  })
};

// 重命名
export const renameNode = (data) => {
  return axios({
    url: '/pipeline/pipeline-tasks/rename',
    method: 'put',
    data
  })
};

// 重绘
export const redrawWorkflow = (data) => {
  return axios({
    url: `/pipeline/pipeline-tasks/pipeline/${data.id}`,
    timeout: 600000000
  })
};

// 删除
export const delNode = (data) => {
  return axios({
    url: `/pipeline/pipeline-tasks/${data.id}`,
    method: 'delete',
    timeout: 600000000
  })
};

// 创建工作流
export const createPipeline = (data) => {
  return axios({
    url: `/pipeline/pipeline-jobs/pipeline/${data.id}`,
    method: 'post',
    timeout: 600000000
  })
};

// 运行工作流
export const runPipeline = (data) => {
  return axios({
    url: `/pipeline/pipeline-jobs/exec/${data.id}`,
    method: 'post',
    timeout: 600000000
  })
};

// 暂停工作流
export const stopPipeline = (data) => {
  return axios({
    url: `/pipeline/pipelines/stop/${data.id}`,
    method: 'get',
    timeout: 600000000
  })
};

// 导入工作流
export const importPipeline = (data) => {
  return axios({
    url: `/pipeline/pipelines/${data.sourceId}/import/${data.targetId}`,
    timeout: 600000000
  })
};

// 查看日志
export const getLogs = (data) => {
  return axios({
    url: `/pipeline/pipelines/logs/${data.id}`,
    timeout: 600000000
  })
};

// 获取文件
export const getDirFilesInfo = (data) => {
  return axios({
    url: `/datavolum/getDirFilesInfo`,
    method: 'get',
    params: data,
    timeout: 600000000
  })
}

// 设置可复用组件
export const setReuseNode = (data) => {
  return axios({
    url: `/pipeline/tasknode/pipeline-tasks`,
    method: 'post',
    data
  })
}

// 获取初始的工作流状态
export const getStatus = (data) => {
  return axios({
    url: `/pipeline/pipelines/lastjob/${data.id}`,
    timeout: 600000000
  })
};

// 从当前节点重新运行
export const restartRun = (data) => {
  return axios({
    url: `/pipeline/pipeline-jobs/restart/${data.pipelineId}/${data.pipelineJobId}/${data.startNodeId}`
  })
};

// 文件上传
export const uploadFile = (data, query) => {
  return originAxios({
    url: `${config.baseURL}/datavolum/localDataUpload`,
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
      Authorization: localStorage.userToken
    },
    withCredentials: true
  })
};
